package com.qingxin.wuye.repertory.action;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.qingxin.sys.action.BaseAction;
import com.qingxin.sys.mvc.PageParam;
import com.qingxin.sys.mvc.SysError;
import com.qingxin.wuye.repertory.entity.ChukuDetail;
import com.qingxin.wuye.repertory.entity.ChukuDocket;
import com.qingxin.wuye.repertory.service.ChukuDetailService;
import com.qingxin.wuye.repertory.service.ChukuDocketService;

@Controller
@RequestMapping("outResMx")
public class ChukuDetailAction extends BaseAction{
	@Autowired
	private ChukuDetailService chukuDetailService;
	@Autowired
	private ChukuDocketService chukuDocketService;
	/**
	 * 明细   
	 * @param model
	 * @param docketid
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/list.do", method=RequestMethod.GET)
	public String index(ModelMap model,String docketid,HttpServletRequest request) {
		model.put("docketid", docketid);
		ChukuDocket chukuDocket  = chukuDocketService.get(docketid);
		model.put("repertoryid", chukuDocket.getRepertoryid());
		return "wuye/outRes/danjuMx/danjuMx_list";
	}
	
	@RequestMapping(value="/listdata.json" , method={RequestMethod.GET, RequestMethod.POST})
	@ResponseBody
	public Object listdata(String searchname,String repertoryid , String docketid,PageParam pageParam, HttpServletRequest request){
		return chukuDetailService.list(searchname,repertoryid,docketid, pageParam, getLoginUser(request));
	}
	
	@RequestMapping(value="/add.do" , method=RequestMethod.GET)
	public String add(ModelMap model,String repertoryid, String docketid,HttpServletRequest request){
		model.put("docketid", docketid);
		model.put("repertoryid", repertoryid);
		return "wuye/outRes/danjuMx/danjuMx_add";
	}
	
	@RequestMapping(value="/save.json", method={RequestMethod.POST})
	@ResponseBody
	public Object save(@Valid ChukuDetail chukuDetail, BindingResult result, HttpServletRequest request){
		if(result.hasErrors()){
			return getSysErrors(result);
		}
		
		SysError info = chukuDetailService.add(chukuDetail, getLoginUser(request), request);
		return info;
	}
	
	@RequestMapping(value="/edit.do" , method=RequestMethod.GET)
	public String edit(ModelMap model,String docketid,String repertoryid, String detailid, HttpServletRequest request){
		ChukuDetail chukuDetail = chukuDetailService.get(detailid);
		model.put("rukuDetail", chukuDetail);
		model.put("repertoryid", repertoryid);
		model.put("docketid", docketid);
		return "wuye/outRes/danjuMx/danjuMx_edit";
	}
	
	
	@RequestMapping(value="/update.json", method={RequestMethod.POST})
	@ResponseBody
	public Object update(@Valid ChukuDetail chukuDetail, BindingResult result, HttpServletRequest request){
		if(result.hasErrors()){
			return getSysErrors(result);
		}
		
		SysError info = chukuDetailService.update(chukuDetail, getLoginUser(request), request);
		return info;
	}
	
	
	@RequestMapping(value="/delete.json", method={RequestMethod.POST})
	@ResponseBody
	public Object delete(String[] detailid, HttpServletRequest request){
		if(detailid==null || detailid.length==0){
			return new SysError("没有选择任何信息.");
		}
		return chukuDetailService.delete(detailid, getLoginUser(request), request);
	}
	
	
}
